<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.beaut.project.util.FlowUtility" %>
<%@ include file="/public/header.jsp"%>

<html>
	<head>
		<title>甲供材出库管理</title>
	</head>
	<script type="text/javascript">
		$(function(){
			$("#searchValue").keypress(function(e) { 
		    	// 回车键事件 
		     	if(e.which == 13) { 
		     		 doSearch();
		       	} 
		   	}); 
			$("#dept_id").combotree({
				url:'<%=contextPath %>/springMVC/group/listDepartment',
				method:'POST',
				animate:true,
				lines:true,
				onChange:function(){
					doSearch();
				}
			});
			$("#table").datagrid({
				title:"甲供材出库管理",
				iconCls:'icon-edit',
				loadMsg:'正在加载数据，请稍后......',
				url:'<%=contextPath %>/springMVC/xm/listPageFlowOutWarehouse',
				rownumbers:true,
				fitColumns:true,
				nowrap:false,
				idField:'id',
				frozenColumns:[[
				    {title:'主键',field:'id',hidden:true}
				]],
				columns:[[
					{title:'创建时间',field:'operation_date',width:200,align:'center'},
					{title:'项目编号',field:'xm_code',width:100,align:'center'},
					{title:'项目名称',field:'xm_name',width:200,align:'center'},
					{title:'客户',field:'customer',width:100,align:'center'},
					{title:'客户id',field:'customer_id',width:5,hidden:true},
					{title:'部门',field:'dept_name',width:200,align:'center'},
					{title:'摘要',field:'remark',width:250,align:'center'},
					{title:'审核状态',field:'status',width:100,align:'center',formatter:function(value,rowData,rowIndex){
						if(value==1){
							return "审核中";
						}else if(value==2){
							return "审核不通过";
						}else if(value==3){
							return "审核通过";
						}
						return "未提交审核";
					}},
					{title:'详情操作',field:'more',width:200,align:'center',formatter:function(value,rowData,rowIndex){
						var str="";
						if(rowData.status == 0  || rowData.status == 2){
							str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-modify' title='编辑' onclick=\"javascript:addOrEditMaterial(1,'"+rowData.id+"','"+rowData.dept_id+"','"+rowData.flag+"','"+rowData.customer_id+"');\"/> &nbsp;&nbsp;";
							str+="<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审批' onclick=\"javascript:shenpi(this,'"+rowData.id+"','"+rowData.flag+"');\"/> &nbsp;&nbsp;";
							if(rowData.status==0){
							str+="<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-no' title='删除' onclick=\"javascript:deleteJGM('"+rowData.id+"');\"/> ";
							}
							return str;
						}
						if(rowData.status >0){
							str+="<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审核查看' onclick=\"javascript:viewFlowView('"+encodeURIComponent("<%=FlowUtility.XM_JGC_SHENPI%>")+"','"+rowData.id+"');\"/>&nbsp;&nbsp;";
							
						}
						if(rowData.status>0){
	                    str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-details' title='详情' onclick=\"javascript:addOrEditMaterial(2,'"+rowData.id+"','"+rowData.dept_id+"','"+rowData.flag+"');\"/>";
						}
						return str;
					}}
				]],
				view: detailview,
				detailFormatter:function(index,row){
					return '<div style="padding:2px"><table class="ddv"></table></div>';
				},
				onExpandRow: function(index,row){
					var request_id = row.id;
					var ddv = $(this).datagrid('getRowDetail',index).find('table.ddv');
					 ddv.datagrid({
						title:'出库明细',
						url:'<%=contextPath%>/springMVC/xm/getXMFlowOutDetail?request_id='+request_id,
						loadMsg:'正在加载数据，请稍后......',
						fitColumns:true,
						rownumbers:true,
						columns:[[
							{title:'产品id',field:'id',hidden:true},
							{title:'产品编号',field:'code',width:200,align:'center'},
							{title:'产品名称',field:'name',width:200,align:'center'},
							{title:'规格/型号',field:'format_type',width:200,align:'center'},
							{title:'单位',field:'unit_name',width:100,align:'center'},
							{title:'库存数量',field:'db_num',width:200,align:'center'},
							{title:'出库数量',field:'num',width:200,align:'center'}
						]],
					 	onResize:function(){
					        $('#table').datagrid('fixDetailRowHeight',index);
					    },
					 	onLoadSuccess:function(){
					       setTimeout(function(){
					         $('#table').datagrid('fixDetailRowHeight',index);
					       },0);
					   }
					 });
					 $('#table').datagrid('fixDetailRowHeight',index);
				},
				pageSize:10,
				pageList : [10,50,100],  
				pagination:true,
				toolbar:"#tb",
				onLoadSuccess:function(rtJson){
					if(rtJson.rtState== '1')
					{
						$.messager.alert('提示',rtJson.rtMsrg);
					}
				}
			});
		});
        function addOrEditMaterial(type,id,dept_id,flag,customer_id){
        	 //var para="xm_id="+id+"&xm_code="+encodeURIComponent(xm_code)+"&xm_name="+encodeURIComponent(xm_name)+"&dept_id="+dept_id+"&dept_name="+encodeURIComponent(dept_name)+"&customer_id="+customer_id+"&customer="+encodeURIComponent(customer);
	        	 if(type==0){
		        	 openDialogResize("<%=contextPath %>/springViews/xm/addOrEditJGOutMaterial.jsp?callback=rtCallBack",1000, 800);
	        	}else if(type==1){
		         	 openDialogResize("<%=contextPath %>/springViews/xm/addOrEditJGOutMaterial.jsp?id="+id+"&dept_id="+dept_id+"&callback=rtCallBack&isShow=0",1000, 800);
	        	}else{
		        	 openDialogResize("<%=contextPath %>/springViews/xm/addOrEditJGOutMaterial.jsp?id="+id+"&callback=rtCallBack&isShow=1",1000, 800);
	        	}
        }
		function shenpi(obj,id,flag){
	    	//flowBusinessUrl获取审批业务记录的URL(可以是个组合参数字符串),moduleFlow获取工作流程的流程名称
	      var flowBusinessUrl="";
	    	if(flag=='1'){
	      			flowBusinessUrl="<%=contextPath %>/springViews/xm/addOrEditJGOutMaterial.jsp?id="+id+"&isShow=1";
	    	}else{
	      			flowBusinessUrl="<%=contextPath %>/springViews/xm/addOrEditBorrowMaterial.jsp?id="+id+"&isShow=1";
	    	}
	      var param="flowBusinessUrl="+encodeURIComponent(flowBusinessUrl)+"&moduleFlow="+encodeURIComponent("<%=FlowUtility.XM_JGC_OUT_SHENPI%>")+"&businessId="+id;
	      $(obj).hide();
	      $.ajax({
						type:'POST',
						url:'<%=contextPath %>/springMVC/workFlow/toShenpi',
						dataType:"JSON",
						data:param,
						success:function(rtJson){
							if (rtJson.rtState == '0'){
								openDialogResize(rtJson.rtData.url,1000,800);
							}else{
								warningInfo(rtJson.rtMsrg);
							}
							$(obj).show();
						}
					});
	       
	    } 
		
		function deleteJGM(id){
			var rows=$('#table').datagrid('getSelections');
			$.messager.confirm('确认','您确认删除该记录信息？',function(msg){
				if(msg){
					$.ajax({
						type:'POST',
						url:"<%=contextPath %>/springMVC/xm/deleteJGOutMaterial",
						data:"id="+id,
						success:function(rtJson){
							if(rtJson.rtState == '0'){
								table_reload(rows.length);
							}
							else{
								warningInfo(rtJson.rtMsrg);
							}
						}
					});
				}
			});
		}


		function rtCallBack(){
			$('#table').datagrid('reload');
		}
		function doSearch()
		{
			var start_time=$('#start_time').datebox('getValue');  
			var end_time=$('#end_time').datebox('getValue');  
			var searchValue = $('#searchValue').val();
			var dept_id = $("#dept_id").combotree('getValue');
			$('#table').datagrid('load',{
				searchValue:searchValue,
				start_time:start_time,
				dept_id :dept_id,
				end_time:end_time
				
			});
		}
	</script>
		<body style="height: 97%">
		<div id="table" data-options="fit:true" ></div>
		<div id="tb" style="padding:3px;height:auto">
			<div style="float:left;">
				<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="addOrEditMaterial(0);">新增</a>
			</div>
			<div align="right">
				所属部门：<input  id="dept_id" name="dept_id" class="easyui-combotree">&nbsp;&nbsp; 
				开始时间：<input id="start_time" name="start_time" class="easyui-datebox" />&nbsp;&nbsp;&nbsp;结束时间：<input id="end_time" name="end_time" class="easyui-datebox" />
				项目编号/名称：<input id="searchValue" name="searchValue" style="width:150px" title="项目编号/名称" placeholder="项目编号/名称 "  />&nbsp;&nbsp; 
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch();"></a>
			</div>
		</div>
	</body>
</html>